<?php

namespace App\Http\Controllers;

use App\Http\Models\User;

class UserController extends Controller
{
    /*
     * 用户授权登录后，存储用户信息
     */
    public function addUser()
    {
        $name = request('name');
        $avatar = request('avatar');
        $data = ['name'=>$name,'avatar'=>$avatar];

        //先查找该用户是否存在
        $user = User::where('name',$name)->first();
        if($user)
        {
            return api_return(2,"该用户已存在",$user);
        }
        $res = User::create($data);
        if(!$res){
            return api_return(0,'登录失败');
        }
        return api_return(1,'登录成功',$res);

    }
}
